<?php

require_once 'bootstrap.php';

class Core_Bootstrap extends Bootstrap
{

    public function __construct()
    {
        $this -> initDb();
        $this -> initSession();
    }

    /**
     * init database
     */
    public function initDb()
    {

        require_once 'Zend/Db.php';
        require_once 'Zend/Db/Table/Abstract.php';

        $db = Zend_Db::factory('pdo_mysql', array(
            'username' => 'nora',
            'password' => 'nora123',
            'dbname' => 'namnv_nuo',
            'port' => 3306,
            'host' => 'localhost'
        ));

        // include the cache class
        require_once ('Zend/Cache.php');

        Zend_Db_Table_Abstract::setDefaultAdapter($db);

        if (null != ($cache = Nuo::getHelper('core@cache') -> getCache('core')))
        {
            Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
        }
        return $db;
    }

    public function initCache()
    {
        return Nuo::getHelper('core@cache');
    }

    /**
     * init session
     */
    public function initSession()
    {
        require_once 'Zend/Session.php';

        if ('db' == SESSION_ADAPTER)
        {
            Session::setSaveHandler(Nuo::getResource('core@session', 'table'));
        }
    }

    /**
     * Initializes translator
     *
     * @return Zend_Translate_Adapter
     */
    public function initTranslate()
    {
        /**
         *
         */
        require_once 'Zend/Translate.php';

        // Set cache
        $cache = Nuo::getHelper('core@cache') -> getCache('core');

        if ($cache)
        {
            // Zend_Translate::setCache($cache);
        }

        // If in development, log untranslated messages
        $params = array(
            'scan' => Zend_Translate_Adapter::LOCALE_FILENAME,
            'logUntranslated' => false
        );

        // Main
        return new Zend_Translate('Csv', NUO_APP_PATH . '/translate/', null, $params);
    }

}
